﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class HoaDonBanLeDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion
        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion
        #region "Khai báo các Method"
        public bool InsertHDBL(HoaDonBanLeDTO HoaDonBanLe)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[8];
            par[0] = new SqlParameter("@MaHDBL", HoaDonBanLe.MaHDBL);            
            par[1] = new SqlParameter("@MaNV", HoaDonBanLe.MaNV);
            par[2] = new SqlParameter("@MaKho", HoaDonBanLe.MaKho);
            par[3] = new SqlParameter("@NgayBanLe", HoaDonBanLe.NgayBanLe);
            par[4] = new SqlParameter("@ChungTubanLe", HoaDonBanLe.ChungTubanLe);
            par[5] = new SqlParameter("@VAT", HoaDonBanLe.VAT);
            par[6] = new SqlParameter("@TongThanhTien", HoaDonBanLe.TongThanhTien);
            par[7] = new SqlParameter("@Quay", HoaDonBanLe.Quay);
            try
            {
                helper.InsertQuery("sp_Insert_HoaDonBanLe", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateHDBL(HoaDonBanLeDTO HoaDonBanLe)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[8];
            par[0] = new SqlParameter("@MaHDBL", HoaDonBanLe.MaHDBL);
            par[1] = new SqlParameter("@MaNV", HoaDonBanLe.MaNV);
            par[2] = new SqlParameter("@MaKho", HoaDonBanLe.MaKho);
            par[3] = new SqlParameter("@NgayBanLe", HoaDonBanLe.NgayBanLe);
            par[4] = new SqlParameter("@ChungTubanLe", HoaDonBanLe.ChungTubanLe);
            par[5] = new SqlParameter("@VAT", HoaDonBanLe.VAT);
            par[6] = new SqlParameter("@TongThanhTien", HoaDonBanLe.TongThanhTien);
            par[7] = new SqlParameter("@Quay", HoaDonBanLe.Quay);
            try
            {
                helper.UpdateQuery("sp_Update_HoaDonBanLe", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteHDBL(string maHDBL)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maHDBL", maHDBL);
            try
            {
                helper.DeleteQuery("sp_Delete_HoaDonBanLe", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_HoaDonBanLe()
        {
            helper = new Helper();
            DataSet ds_HDBL = helper.SelectQuery("sp_LayDS_HoaDonBanLe");
            return ds_HDBL;
        }
        #endregion
    }
}